package com.per.mybootall.controller;

import com.per.mybootall.Interceptor.MyNote;
import com.per.mybootall.dao.OrderMapper;
import com.per.mybootall.pojo.Order;
import com.per.mybootall.service.OrderInter;
import com.per.mybootall.utils.BigDecimalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;

@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderInter orderInter;
@Autowired
private OrderMapper orderMapper;

    //创建订单
    @PostMapping("/creatOrder")
    public String creatOrder(String usertoken,String whoareuser,Long userid,Integer productid,Integer productNumber,double producrPrice){

        System.out.println("creat Order params:"+usertoken+";"+whoareuser+";"+userid+";"+producrPrice+";"+productNumber+";"+producrPrice);

        if(orderInter.creatOrder( usertoken, whoareuser, userid, productid, productNumber, producrPrice)>=1){
           String msg="创建订单成功";
            return msg;
        }
        String msg="创建订单失败";
        return msg;
    }



    /*小测试==》无关紧要*/
    @MyNote()
    @GetMapping("/testMybitsID")
    public String tests(String userid){
      Order  order =new Order();
      order.setPayWhat(0);order.setOrderEtat(0);order.setUserId((long) 2);order.setProductNumber(1);
      order.setProductId(4);order.setAllnumberPay(BigDecimalUtil.mul(6,6));
     //  int k=orderMapper.insertBackId(order);
       // System.out.println("自增id:"+k);
        return "kk";
    }

}
